package oldCar;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ling
 * Date: 2022-11-07
 * Time: 14:50
 */
public class oldCarExample2 {
    static class Car {
        private Framework framework;
        public Car(int size) {
            framework = new Framework(size);
        }
        public void init () {
            //依赖车身
            framework.init();
            System.out.println("车子启动");
        }
    }

    /**
     * 车身类
     */
    static class Framework {
        private Bottom bottom;
        public Framework(int size) {
            bottom = new Bottom(size);
        }
        public void init() {
            //依赖底盘
            bottom.init();
            System.out.println("车身类启动");
        }
    }

    /**
     * 底盘类
     */
    static class Bottom {
        private Tire tire;
        private Bottom(int size) {
            tire = new Tire(size);
        }
        public void init() {
            //依赖轮胎
            tire.init();
            System.out.println("底盘类启动");
        }
    }

    /**
     * 轮胎类
     */
    static class Tire {
        private int size =15;//轮胎尺寸
        public Tire (int size) {
            this.size=size;
        }
        public void init() {
            System.out.println("轮胎尺寸"+size);
        }
    }

    public static void main(String[] args) {
        Car car = new Car(20);//让用户自己定轮胎尺寸
        car.init();
    }
}
